<?php 
$rows_per_page = 15;
$page_start = ( $page - 1 ) * $rows_per_page; 
$page_end = $page * $rows_per_page;

$list_projectPage = mysql_query("SELECT p.IDProject, p.NameProject, p.Description, p.DateStart, p.DateComplete, p.IDManager, p.`Status`, e.FullName 
        	FROM pr_project p,employee e WHERE p.IDManager = e.IDEmployee ORDER BY p.IDProject ASC");

$list_project = mysql_query("SELECT p.IDProject, p.NameProject, p.Description, p.DateStart, p.DateComplete, p.IDManager, p.`Status`, e.FullName 
        	FROM pr_project p,employee e WHERE p.IDManager = e.IDEmployee ORDER BY p.IDProject ASC limit ".$page_start.",".$rows_per_page);

$number_of_page_projects = ceil ( mysql_num_rows( $list_projectPage ) / $rows_per_page );

unset($_SESSION['addTester']);
unset($_SESSION['addCoder']);
unset($_SESSION['listcomposition']);

?>
<script type="text/javascript">


function ajaxDeleteProject(projectid){
	var l_detail = $('input#l_detail').val();
	var l_update = $('input#l_update').val();
	var l_delete = $('input#l_delete').val();
	$.ajax({url:"admin/project/ajaxdeleteproject.php", data : {pro_id : projectid, l_update : l_update, l_delete : l_delete , l_detail : l_detail}, success:function(result){
		$("table#listproject tr:not(:first)").remove();
		$("table#listproject tbody").append(result);
	}});
}
function paging(page, eleID){
	var l_detail = $('input#l_detail').val();
	var l_update = $('input#l_update').val();
	var l_delete = $('input#l_delete').val();
	$.ajax({url:"admin/project/ajaxpagingproject.php", data : {pages : page, l_update : l_update, l_delete : l_delete , l_detail : l_detail}, success:function(result){
		$("table#listproject tr:not(:first)").remove();
		$("table#listproject tbody").append(result);
	}});
}
</script>

<div id="contains" style="background-color: #edf4f7;">

	<div class="title"></div>
	<div class="main_content"  style="min-height: 895px">  
		<div class="tr_title"><?=$l_projectlist?> </div>	
		<input type="hidden" value="<?=$l_detail?>" id="l_detail"/>	
		<input type="hidden" value="<?=$l_update?>" id="l_update"/>	
		<input type="hidden" value="<?=$l_delete?>" id="l_delete"/>	
        <div>
        	<table cellpadding="5" cellspacing="0" class="rf_dt" id="listproject">
                <tr  class="table_new">
                <td width="10%"><?=$l_code?></td>
                <td width="15%"><?=$l_project_name?></td>
                <td width="15%"><?=$l_manager?></td>
                <td width="15%"><?=$l_status?></td>
                <td width="13%"><?=$l_start_date?></td>
                <td width="13%"><?=$l_complete_date?></td>
                <td width="19%"></td>
                </tr>
                <?php while ($row=mysql_fetch_array($list_project)){ 
					$pro_id = $row['IDProject'];
					$pro_name =$row['NameProject'];
					$pro_manager =$row['FullName'];
					if ($row['Status']==0) {
						$pro_status = $l_status_project_no;
					}else{
						$pro_status = $l_status_project_done;
					}
					$pro_startdate =$row['DateStart'];
					$pro_completedate =$row['DateComplete'];
				?>
                <tr>
                <td align="center"><a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$pro_id?>"><?php echo $pro_id;?></a></td>
                <td align="center"><a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$pro_id?>"><?php echo $pro_name;?></a></td>
                <td align="center"><?php echo $pro_manager;?></td>
                <td align="center"><?php echo $pro_status;?></td>
                <td align="center"><?php echo $pro_startdate;?></td>
                <td align="center"><?=$pro_completedate?></td>
                <td align="center">
                	
                	<a href="project_admin.php?content=admin/project/newproject.php&id=<?=$pro_id?>"><span class="buttonProject" style="padding: 5px; border:1px solid #999"><?=$l_update?></span></a>
                	<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$pro_id?>"><span class="buttonProject" style="padding: 5px; border:1px solid #999"><?=$l_detail?> </span></a>
                	<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="if(confirm('Are you sure?')){  ajaxDeleteProject(<?=$pro_id?>)}" class="buttonProject" style="padding: 5px; border:1px solid #999"><?=$l_delete?></span>
                	 
                </td>
                </tr>
                <?php }?>
                <tr class="trfoot">
	                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="7">
	                        	<div style="text-align: center; width: 100%">
	                            	<span class="rf-ds">
															
															<?php if ( $number_of_page_projects > 1 ) 
															{ 
																if ($page==1)
																	$p=2;
																else if ($page==$number_of_page_projects)
																	$p=$number_of_page_projects-1;
																else $p=$page;
																if($page!=1){?>
																	<a onclick="paging(1,'#listproject')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																	<a onclick="paging(<?=($page-1)?>,'#listproject')" ><span class='button_next'><?php echo "<<";?></span> </a>
																<?php  }
																else{
																	echo "<span class='button_next'><<<</span>"; 
																	echo "<span class='button_next'><<</span>";
																}
																for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																		if ($i<=$number_of_page_projects && $i>0)
																		
																			if ($i==$page){
																				echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																			}else{
																			?>
																				<a onclick="paging(<?=$i?>,'#listproject')" ><span class="button_next">
																				<?php 
																				echo $i;
																				?>
																				</span> </a>
																			<?php 
																			}
																		?>
																	
																<?php 
																		}
																	
																	if($page!=$number_of_page_projects){ ?>
																		<a onclick="paging(<?=($page+1)?>,'#listproject')"><span class='button_next'><?php echo ">>";?></span> </a>
																		<a onclick="paging(<?=($number_of_page_projects)?>,'#listproject')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																	<?php }
																	else{
																		echo "<span class='button_next'>>></span> ";
																		echo "<span class='button_next'>>>></span> ";
																	}
																}
															
																
																?>
																													
														</span>
														</div>
														</td>
	                    </tr> 
            </table>
        </div>
           
</div>	
	
	
</div>

